# -*- coding:UTF-8 -*-

import os
import configparser
import logging

logging.basicConfig(filename="./log/processconf.log", filemode='w',
                    format='%(asctime)s : %(levelname)s : %(message)s',
                    level=logging.DEBUG)

class ProsConf:
    def __init__(self):
        self.config = configparser.ConfigParser()
        os.chdir(os.getcwd())
        self.confile = os.path.join(os.getcwd(),"confile", "config.ini")
        self.config.read(self.confile, encoding='utf-8-sig')

    def open_confile(self):
        try:
            with open(self.confile, 'r', encoding='utf-8-sig') as f:
                line = f.read()
                return line
        except BaseException as e:
            logging.error(e)

    def save_confile(self, value):
        try:
            with open(self.confile, 'w', encoding='utf-8-sig') as f:
                f.write(value)
                logging.info(value)
        except BaseException as e :
            logging.error(e)

    def get_section_dict(self, section):
        try:
            dictvalue = self.config.items(section)
            return dictvalue
        except BaseException as e:
            logging.error(e)
